package com.woniuxy.ams.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.ams.entity.*;
import com.woniuxy.ams.service.DailyAssessDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dailyAssess")
public class DailyAssessDetailsController {
    /**
     * 使用注解自动注入 DailyAssessDetailsService 日考核详情表
     */
    DailyAssessDetailsService dailyAssessDetailsService;
    @Autowired(required = false)
    public void setDailyAssessDetailsService(DailyAssessDetailsService dailyAssessDetailsService) {
        this.dailyAssessDetailsService = dailyAssessDetailsService;
    }

    /**+
     * 添加日考核业务！
     * @param dailyAssessDetails
     * @return
     */
    @RequestMapping("/insert")
    public ResultEntity<Integer> insertDailyAssessDetail(@RequestBody DailyAssessDetails dailyAssessDetails){
        dailyAssessDetails.toString();
        int code = dailyAssessDetailsService.insert(dailyAssessDetails);
        if (code==0){
            return new ResultEntity<>(400,"新增失败",code);
        }else {
            return new ResultEntity<>(200,"新增成功!",code);
        }
    }

    /**
     * 查看日考核详情业务
     */
    @RequestMapping("/findAll")
    public ResultEntity<PageInfo<DailyAssessDetails>> findAllDailyAssess(@RequestBody PageRequest pageRequest){
        PageHelper.startPage(pageRequest.getCurrentPage(), pageRequest.getLimit());
        List<DailyAssessDetails> dailyAssessDetails = dailyAssessDetailsService.findDailyAssessPageAndAll();
        PageInfo<DailyAssessDetails> dailyAssessDetailsPageInfo = new PageInfo<>(dailyAssessDetails);
        return new ResultEntity<>(200,"查询成功",dailyAssessDetailsPageInfo);
    }
    /**
     * 查看日考核详情业务
     */
    @RequestMapping("/findAlNotCheck")
    public ResultEntity<PageInfo<DailyAssessDetails>> findAlNotCheck(@RequestBody PageRequest pageRequest){
        PageHelper.startPage(pageRequest.getCurrentPage(), pageRequest.getLimit());
        List<DailyAssessDetails> dailyAssessDetails = dailyAssessDetailsService.findAlNotCheck();
        PageInfo<DailyAssessDetails> dailyAssessDetailsPageInfo = new PageInfo<>(dailyAssessDetails);
        return new ResultEntity<>(200,"查询成功",dailyAssessDetailsPageInfo);
    }

    /**
     *  个人日考核汇总
     */
    @RequestMapping("/summarize")
    public ResultEntity<PageInfo<DailyAssessSummarize>> findSummarize( @RequestBody PageRequest<DailyAssessSummarize> pageRequest ){
        PageHelper.startPage(pageRequest.getCurrentPage(), pageRequest.getLimit());
        DailyAssessSummarize dailyAssessSummarize = pageRequest.getData();
        List<DailyAssessSummarize> list = dailyAssessDetailsService.findSummarize(dailyAssessSummarize);
        PageInfo<DailyAssessSummarize> dailyAssessSummarizePageInfo = new PageInfo<>(list);
        return new ResultEntity<>(200,"查询成功！",dailyAssessSummarizePageInfo);
    }

    /**
     * 修改日考核部分信息
     */
    @RequestMapping("/update")
    public ResultEntity<Integer> updateDynamic(@RequestBody DailyAssessDetails dailyAssessDetails){
        int code  =   dailyAssessDetailsService.update(dailyAssessDetails);
        if (code==0){
            return new ResultEntity<>(400,"新增失败",code);
        }else {
            return new ResultEntity<>(200,"新增成功!",code);
        }
    }

    /**
     * 批量审核方法
     */
    @RequestMapping("/updateAssess")
    public  ResultEntity<Integer> updateAssess(@RequestBody List<DailyAssessDetails> objList){
        Integer code  = dailyAssessDetailsService.checkAssess(objList);
        return new ResultEntity<>(200,"审核成功！",code);
    }
    /**
     * 删除日考核以及其关联的表
     */
    @RequestMapping("/delete")
    public ResultEntity<Integer> deleteAssessDetails(@RequestBody DailyAssessDetails dailyAssessDetails){
        int code = dailyAssessDetailsService.deleteAssessDetail(dailyAssessDetails);
        if (code==0){
            return new ResultEntity<>(400,"删除失败！",code);
        }else {
            return new ResultEntity<>(200,"删除成功!",code);
        }
    }

    /**
     * 有条件搜索
     */
    @RequestMapping("/findConditional")
    public ResultEntity<List<DailyAssessDetails>> findAssessDetailFuzzy(@RequestBody  DailyAssessDetails dailyAssessDetails){
        dailyAssessDetails.toString();
        List<DailyAssessDetails> list = dailyAssessDetailsService.findAssessDetailFuzzy(dailyAssessDetails);
        return new ResultEntity<>(200,"搜索成功！",list);
    }

    /**
     * 通过id去查询
     * @param id
     * @return
     */
    @RequestMapping("/findById")
    public  ResultEntity<DailyAssessDetails> findById(@RequestParam("id") String id){
        DailyAssessDetails dailyAssessDetails =  dailyAssessDetailsService.findById(id);
        return new ResultEntity<>(200,"查询成功！",dailyAssessDetails);
    }
}
